<template>
  <Form :model="formItem" :rules="ruleInline" :label-width="80" ref="lesson_form">
    <Alert show-icon>
      基本信息
      <Icon type="ios-lightbulb-outline" slot="icon"></Icon>
    </Alert>
    <FormItem label="课程编号" prop="code" style="margin-top: 20px;">
      <Input v-model="formItem.code" placeholder="请输入课程编号..."></Input>
    </FormItem>
    <FormItem label="课程名称" prop="name" style="margin-top: 20px;">
      <Input v-model="formItem.name" placeholder="请输入课程名称..."></Input>
    </FormItem>
    <FormItem label="课程发布状态 0:未发布（默认） 1:已发布" prop="status" style="margin-top: 20px;">
      <Input v-model="formItem.status" placeholder="请输入课程发布状态 0:未发布（默认） 1:已发布..."></Input>
    </FormItem>
    <FormItem label="学习天数" prop="allowday" style="margin-top: 20px;">
      <Input v-model="formItem.allowday" placeholder="请输入学习天数..."></Input>
    </FormItem>
    <FormItem label="通过分数" prop="mark" style="margin-top: 20px;">
      <Input v-model="formItem.mark" placeholder="请输入通过分数..."></Input>
    </FormItem>
    <FormItem label="课程费用" prop="cost" style="margin-top: 20px;">
      <Input v-model="formItem.cost" placeholder="请输入课程费用..."></Input>
    </FormItem>
    <FormItem label="学时" prop="hour" style="margin-top: 20px;">
      <Input v-model="formItem.hour" placeholder="请输入学时..."></Input>
    </FormItem>
    <FormItem label="是否公开课 0:否1:是（默认）" prop="isopen" style="margin-top: 20px;">
      <Input v-model="formItem.isopen" placeholder="请输入是否公开课 0:否1:是（默认）..."></Input>
    </FormItem>
    <FormItem label="使用对象" prop="objectable" style="margin-top: 20px;">
      <Input v-model="formItem.objectable" placeholder="请输入使用对象..."></Input>
    </FormItem>
    <FormItem label="通过分数" prop="maker" style="margin-top: 20px;">
      <Input v-model="formItem.maker" placeholder="请输入通过分数..."></Input>
    </FormItem>
    <FormItem label="备注" prop="remark" style="margin-top: 20px;">
      <Input v-model="formItem.remark" placeholder="请输入备注..."></Input>
    </FormItem>
    <FormItem label="课程类型 2  单一入口课件4  scorm课件 " prop="kj_type" style="margin-top: 20px;">
      <Input v-model="formItem.kj_type" placeholder="请输入课程类型 2  单一入口课件4  scorm课件 ..."></Input>
    </FormItem>
    <FormItem label="单一入口课件的url" prop="enter_url" style="margin-top: 20px;">
      <Input v-model="formItem.enter_url" placeholder="请输入单一入口课件的url..."></Input>
    </FormItem>
    <FormItem label="培训目标" prop="training_target" style="margin-top: 20px;">
      <Input v-model="formItem.training_target" placeholder="请输入培训目标..."></Input>
    </FormItem>
    <FormItem label="主要内容" prop="training_comment" style="margin-top: 20px;">
      <Input v-model="formItem.training_comment" placeholder="请输入主要内容..."></Input>
    </FormItem>
    <FormItem label="培训方式" prop="training_manner" style="margin-top: 20px;">
      <Input v-model="formItem.training_manner" placeholder="请输入培训方式..."></Input>
    </FormItem>
    <FormItem label="允许退课时间范围（已废除，退课不做时间限制）" prop="handbacktime" style="margin-top: 20px;">
      <Input v-model="formItem.handbacktime" placeholder="请输入允许退课时间范围（已废除，退课不做时间限制）..."></Input>
    </FormItem>
    <FormItem label="是否可以预览 0:不可预览 1:可以预览（默认）" prop="ispermit_preview" style="margin-top: 20px;">
      <Input v-model="formItem.ispermit_preview" placeholder="请输入是否可以预览 0:不可预览 1:可以预览（默认）..."></Input>
    </FormItem>
    <FormItem label="是否微课件 1:否(默认）2:是" prop="ismini" style="margin-top: 20px;">
      <Input v-model="formItem.ismini" placeholder="请输入是否微课件 1:否(默认）2:是..."></Input>
    </FormItem>
    <FormItem label="终端类型1:pc终端 2：移动终端 3：pc和移动终端" prop="terminaltype" style="margin-top: 20px;">
      <Input v-model="formItem.terminaltype" placeholder="请输入终端类型1:pc终端 2：移动终端 3：pc和移动终端..."></Input>
    </FormItem>
    <FormItem label="pc终端和移动终端视频名称" prop="path" style="margin-top: 20px;">
      <Input v-model="formItem.path" placeholder="请输入pc终端和移动终端视频名称..."></Input>
    </FormItem>
    <FormItem label="课件提供商（手动输入）" prop="coursewareprovider" style="margin-top: 20px;">
      <Input v-model="formItem.coursewareprovider" placeholder="请输入课件提供商（手动输入）..."></Input>
    </FormItem>
    <FormItem label="出版日期" prop="publishdate" style="margin-top: 20px;">
      <DatePicker type="date" placeholder="请输入出版日期..." style="width: 300px" clearable size="large"
                  @on-change="handle_publishdate" editable></DatePicker>
    </FormItem>
    <FormItem label="课程版本 默认1.0" prop="versioncode" style="margin-top: 20px;">
      <Input v-model="formItem.versioncode" placeholder="请输入课程版本 默认1.0..."></Input>
    </FormItem>
    <FormItem label="语种 默认：汉语" prop="languagetype" style="margin-top: 20px;">
      <Input v-model="formItem.languagetype" placeholder="请输入语种 默认：汉语..."></Input>
    </FormItem>
    <FormItem label="课程关键字" prop="keyword" style="margin-top: 20px;">
      <Input v-model="formItem.keyword" placeholder="请输入课程关键字..."></Input>
    </FormItem>
    <FormItem label="作者" prop="author" style="margin-top: 20px;">
      <Input v-model="formItem.author" placeholder="请输入作者..."></Input>
    </FormItem>
    <FormItem label="控制课件显示类型（三分屏、二分屏）" prop="selfnavigator" style="margin-top: 20px;">
      <Input v-model="formItem.selfnavigator" placeholder="请输入控制课件显示类型（三分屏、二分屏）..."></Input>
    </FormItem>
    <FormItem label="课程页面控制参数" prop="selfindexlink" style="margin-top: 20px;">
      <Input v-model="formItem.selfindexlink" placeholder="请输入课程页面控制参数..."></Input>
    </FormItem>
    <FormItem label="讲师" prop="teacher" style="margin-top: 20px;">
      <Input v-model="formItem.teacher" placeholder="请输入讲师..."></Input>
    </FormItem>
    <FormItem label="课程封面图片" prop="lesson_img" style="margin-top: 20px;">
      <Input v-model="formItem.lesson_img" placeholder="请输入课程封面图片..."></Input>
    </FormItem>
    <FormItem label="1 本地路径    0 网络路径" prop="urluptype" style="margin-top: 20px;">
      <Input v-model="formItem.urluptype" placeholder="请输入1 本地路径    0 网络路径..."></Input>
    </FormItem>
    <FormItem label="学分" prop="score" style="margin-top: 20px;">
      <Input v-model="formItem.score" placeholder="请输入学分..."></Input>
    </FormItem>
    <FormItem label="资源列表" prop="resourceids" style="margin-top: 20px;">
      <Input v-model="formItem.resourceids" placeholder="请输入资源列表..."></Input>
    </FormItem>
    <FormItem label="mp4小节数量" prop="kj_count" style="margin-top: 20px;">
      <Input v-model="formItem.kj_count" placeholder="请输入mp4小节数量..."></Input>
    </FormItem>
    <FormItem label="建立课程时上传的文件名" prop="file" style="margin-top: 20px;">
      <Input v-model="formItem.file" placeholder="请输入建立课程时上传的文件名..."></Input>
    </FormItem>
    <FormItem>
      <Button type="primary" @click="handleSubmit">提交</Button>
      <Button type="primary" @click="handleReturn" style="margin-left: 8px">返回</Button>
      <Button type="primary" @click="handleReset" style="margin-left: 8px">清空</Button>
    </FormItem>
  </Form>
</template>
<script>
  export default {
    data() {
      return {
        formItem: {
          lesson_id: "",
          lesson_code: "",
          lesson_name: "",
          lesson_status: "",
          lesson_allowday: "",
          lesson_mark: "",
          lesson_cost: "",
          lesson_hour: "",
          lesson_isopen: "",
          lesson_objectable: "",
          lesson_maker: "",
          lesson_remark: "",
          lesson_kj_type: "",
          lesson_enter_url: "",
          lesson_training_target: "",
          lesson_training_comment: "",
          lesson_training_manner: "",
          lesson_handbacktime: "",
          lesson_ispermit_preview: "",
          lesson_ismini: "",
          lesson_terminaltype: "",
          lesson_path: "",
          lesson_coursewareprovider: "",
          lesson_publishdate: "",
          lesson_versioncode: "",
          lesson_languagetype: "",
          lesson_keyword: "",
          lesson_author: "",
          lesson_selfnavigator: "",
          lesson_selfindexlink: "",
          lesson_teacher: "",
          lesson_lesson_img: "",
          lesson_urluptype: "",
          lesson_score: "",
          lesson_resourceids: "",
          lesson_kj_count: "",
          lesson_file: "",
        },
        ruleInline: {
          code: [
            {required: true, message: '此项为必添项!', trigger: 'blur'},
            {max: 50, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          name: [
            {required: true, message: '此项为必添项!', trigger: 'blur'},
            {max: 200, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          status: [
            {required: true, message: '此项为必添项!', trigger: 'blur'},
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          allowday: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          mark: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          cost: [
            {max: 10, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          hour: [
            {max: 5, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          isopen: [
            {required: true, message: '此项为必添项!', trigger: 'blur'},
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          objectable: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          maker: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          creator: [
            {max: 36, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          remark: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          kj_type: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          create_time: [],
          enter_url: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          training_target: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          training_comment: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          training_manner: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          handbacktime: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          ispermit_preview: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          ismini: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          terminaltype: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          path: [
            {max: 100, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          coursewareprovider: [
            {max: 100, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          publishdate: [],
          versioncode: [
            {max: 20, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          languagetype: [
            {max: 50, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          keyword: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          author: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          selfnavigator: [
            {max: 10, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          selfindexlink: [
            {max: 10, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          teacher: [
            {max: 20, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          group_id: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          lesson_img: [
            {max: 100, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          urluptype: [
            {max: 10, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          score: [
            {max: 19, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          resourceids: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
          kj_count: [
            {max: 10, message: '长度不可以超过100!', trigger: 'blur'},
            {pattern: "^[1-9]\d*$", message: '必须是数字!', trigger: 'blur'},
          ],
          file: [
            {max: 500, message: '长度不可以超过100!', trigger: 'blur'},
          ],
        }
      }
    },
    beforeCreate: function () {
      this.$Spin.show();
    },
    created: function () {
      const id = this.params.id;
      if ("" != id) {//这个说明是修改，要发请求获得更有的数据
        this.$http.get(this.apiUrl() + 'lesson/get/' + id, {}, {
          emulateJSON: true
        }).then((response) => {
          if (response && response.body.success) {
            this.formItem.id = response.body.lesson.id;
            this.formItem.code = response.body.lesson.code;
            this.formItem.name = response.body.lesson.name;
            this.formItem.status = response.body.lesson.status;
            this.formItem.allowday = response.body.lesson.allowday;
            this.formItem.mark = response.body.lesson.mark;
            this.formItem.cost = response.body.lesson.cost;
            this.formItem.hour = response.body.lesson.hour;
            this.formItem.isopen = response.body.lesson.isopen;
            this.formItem.objectable = response.body.lesson.objectable;
            this.formItem.maker = response.body.lesson.maker;
            this.formItem.remark = response.body.lesson.remark;
            this.formItem.kj_type = response.body.lesson.kj_type;
            this.formItem.enter_url = response.body.lesson.enter_url;
            this.formItem.training_target = response.body.lesson.training_target;
            this.formItem.training_comment = response.body.lesson.training_comment;
            this.formItem.training_manner = response.body.lesson.training_manner;
            this.formItem.handbacktime = response.body.lesson.handbacktime;
            this.formItem.ispermit_preview = response.body.lesson.ispermit_preview;
            this.formItem.ismini = response.body.lesson.ismini;
            this.formItem.terminaltype = response.body.lesson.terminaltype;
            this.formItem.path = response.body.lesson.path;
            this.formItem.coursewareprovider = response.body.lesson.coursewareprovider;
            this.formItem.publishdate = response.body.lesson.publishdate;
            this.formItem.versioncode = response.body.lesson.versioncode;
            this.formItem.languagetype = response.body.lesson.languagetype;
            this.formItem.keyword = response.body.lesson.keyword;
            this.formItem.author = response.body.lesson.author;
            this.formItem.selfnavigator = response.body.lesson.selfnavigator;
            this.formItem.selfindexlink = response.body.lesson.selfindexlink;
            this.formItem.teacher = response.body.lesson.teacher;
            this.formItem.lesson_img = response.body.lesson.lesson_img;
            this.formItem.urluptype = response.body.lesson.urluptype;
            this.formItem.score = response.body.lesson.score;
            this.formItem.resourceids = response.body.lesson.resourceids;
            this.formItem.kj_count = response.body.lesson.kj_count;
            this.formItem.file = response.body.lesson.file;
          } else {
            if (response.body.msg === 'session-timeout') {
              window.location.href = "/";
            } else {
              this.$Notice.error({title: "错误", desc: response.body.msg});
            }
            this.$Spin.hide();
          }
        });
      } else {
        this.$Spin.hide();
      }
    },
    methods: {
      handle_publishdate: function (changeValue, date) {
        this.publishdate = changeValue;
      },
      handleSubmit: function () {
        this.$refs['lesson_form'].validate((valid) => {
          if (valid) {
            this.$http.post(this.apiUrl() + 'lesson/save/', {
              id: this.formItem.id,
              code: this.formItem.code,
              name: this.formItem.name,
              status: this.formItem.status,
              allowday: this.formItem.allowday,
              mark: this.formItem.mark,
              cost: this.formItem.cost,
              hour: this.formItem.hour,
              isopen: this.formItem.isopen,
              objectable: this.formItem.objectable,
              maker: this.formItem.maker,
              remark: this.formItem.remark,
              kj_type: this.formItem.kj_type,
              enter_url: this.formItem.enter_url,
              training_target: this.formItem.training_target,
              training_comment: this.formItem.training_comment,
              training_manner: this.formItem.training_manner,
              handbacktime: this.formItem.handbacktime,
              ispermit_preview: this.formItem.ispermit_preview,
              ismini: this.formItem.ismini,
              terminaltype: this.formItem.terminaltype,
              path: this.formItem.path,
              coursewareprovider: this.formItem.coursewareprovider,
              publishdate: this.formItem.publishdate,
              versioncode: this.formItem.versioncode,
              languagetype: this.formItem.languagetype,
              keyword: this.formItem.keyword,
              author: this.formItem.author,
              selfnavigator: this.formItem.selfnavigator,
              selfindexlink: this.formItem.selfindexlink,
              teacher: this.formItem.teacher,
              lesson_img: this.formItem.lesson_img,
              urluptype: this.formItem.urluptype,
              score: this.formItem.score,
              resourceids: this.formItem.resourceids,
              kj_count: this.formItem.kj_count,
              file: this.formItem.file,
            }, {
              emulateJSON: true
            }).then((response) => {
              if (response.body.success) {
                this.$Message.success(response.body.msg);
                this.$emit('childClickMenu', '这里自己写', '这里自己写', 'lesson_list');
              } else {
                this.$Notice.error({title: '错误', desc: response.body.msg});
              }
            });
          } else {
            this.$Notice.error({title: '错误', desc: '请输入完事信息后进行提交!'});
          }
        })
      },
      handleReturn: function () {
        this.$emit('childClickMenu', '自己写', '自己写', 'lesson_list');
      },
      handleReset: function () {
        this.$refs['lesson_form'].resetFields();
      }
    },
    props: ['params']
  }
</script>
<style scoped>
  page_tools {
    float: right;
    padding-top: 10px;
    padding-bottom: 10px;
  }
</style>
